package yf.mall.dao;

import com.yf.dao.BaseDao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import yf.mall.entity.MallOrderEntity;
import yf.mall.vo.MallOrderVo;
import org.apache.ibatis.annotations.Mapper;
import yf.mall.vo.web.OrderVO;
import yf.mall.vo.down.SaleDown;
import yf.mall.vo.down.SendDownVo;
import yf.mall.vo.sum.SendGoodsVo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 商品订单Dao
 *
 *
 *
 * @date Tue Aug 13 14:26:20 CST 2019
 */
@Mapper
public interface MallOrderDao extends BaseDao<MallOrderEntity> {

    List<MallOrderVo> queryListVo(MallOrderVo mallOrderVo);

    MallOrderVo getVo(Long id);

    List<MallOrderVo> findByUserId(@Param("userId") Long userId,@Param("orderType")Integer orderType,@Param("busType")Integer busType);

    //找出未发货的订单
    List<MallOrderEntity> findNotDelivered(@Param("fromUserId") Long fromUserId);

    //找出商城下单且支付了的
    List<MallOrderEntity> findUserPaid(@Param("userId") Long userId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    //更新状态
    void updateDelivering(@Param("ids") List<Long> ids);

    MallOrderVo getVoByOrderNo(String orderNo);

    //根据订单编号查找
    MallOrderEntity findByOrderNo(String orderNo);


    List<MallOrderEntity> findByRemark(String orderNo);

    //恢复定点杆
    void renew(@Param("fromUserId") Long fromUserId);

    List<MallOrderVo> queryByUserIdAndStatus(@Param("userId") Long userId,@Param("status") int status);

   MallOrderEntity findByRemarkAndBusType(@Param("orderNo") String orderNo, @Param("busType") Integer busType);

    List<MallOrderVo> queryByUserIdAndPayStatus(@Param("userId")Long userId, @Param("orderStatus") Integer orderStatus, @Param("payStatus")Integer payStatus);

    Integer total(@Param("userId") Long userId, @Param("orderStatus") int orderStatus, @Param("payStatus") int payStatus);

    List<MallOrderVo> findByFromUserId(Long userId, Integer orderStatus, int payStatus);

    List<MallOrderEntity> findByYerterday(String orderTime);



    Integer totalOrderNum(Long userId);

    Integer todayOrderNum(Long userId);

    BigDecimal totalPrice(Long userId);

    BigDecimal todayPrice(Long userId);

    List<MallOrderEntity> autoCancel();

    Integer sumBuyOrderByPid(Long userId);


    List<SendGoodsVo> sumSendGoods(@Param("name") String name, @Param("date") String date);

    List<SaleDown> downSale(@Param("code") String code, @Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<SaleDown> findByDate(@Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<SendDownVo> findOrderByDate(@Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<MallOrderEntity> findOrder(@Param("startDate") Date startDate, @Param("endDate") Date endDate);

    List<OrderVO> listByType(@Param("userId") Long userId, @Param("page") Integer page, @Param("limit") Integer limit, @Param("payStatus") Integer payStatus, @Param("orderStatus") Integer orderStatus);

    OrderVO getVO(Long userId, Long id);

    @Select("select id from  mall_order where  order_no = #{orderNo}")
    MallOrderEntity findIdByOrderNo(String orderNo);

    @Select("select id,user_id,price,order_time,order_status from mall_order as mo where DATE_FORMAT(mo.order_time,'%Y-%m') = DATE_FORMAT(#{date},'%Y-%m') and pay_status = 1 and  bus_type = 0 order by id")
    List<MallOrderEntity> findByMonth(Date date);

    @Update("update mall_order set ada = #{payName} where order_no = #{orderNo} ")
    void updateAda(@Param("orderNo") String orderNo, @Param("payName") String payName);

    @Select("select ada from mall_order where  order_no = #{orderNo}")
    String findAda(String orderNo);
}
